

const {ccclass, property} = cc._decorator;

@ccclass
export default class RegisterPanel extends cc.Component {

    @property(cc.EditBox)
    namebox: cc.EditBox = null;

    @property(cc.EditBox)
    accountbox: cc.EditBox = null;
    
    @property(cc.EditBox)
    passwordbox: cc.EditBox = null;
    
    @property(cc.EditBox)
    passwordrecheckbox: cc.EditBox = null;
    
    onEnable(){
        cc.vv.eventCustom.on("openHall", ()=>{
            this.node.removeFromParent();
            this.node.destroy()
        }, this.node); 
    }
    start () {
    }

    private onClickregister(): void {
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
		let tempResult: string = ""
        tempResult = this.namebox.string
        if (!cc.vv.GLUtils.checkChineseAndEnglishAndNumber(tempResult)) {
            cc.vv.GLUtils.showTips("昵称只能输入中文，字母和数字!");
            return
        }
        tempResult = this.accountbox.string
        if (!cc.vv.GLUtils.checkEnglishAndNumber(tempResult)) {
            cc.vv.GLUtils.showTips("账号只能输入字母和数字!");
            return
        }
		tempResult = this.passwordbox.string
        if (!cc.vv.GLUtils.checkEnglishAndNumber(tempResult)) {
            cc.vv.GLUtils.showTips("密码只能输入字母和数字!");
            return
        }
        if (this.passwordbox.string!=this.passwordrecheckbox.string) {
            cc.vv.GLUtils.showTips("两次密码不一致!");
            return
        }
       var  len = this.passwordbox.string.length;
        if (len < 8 || len > 16) {
            cc.vv.GLUtils.showTips("请输入8-16位的密码!");
            return
        }

		let data = {
			account: this.accountbox.string,
			password: this.passwordbox.string
		}

		cc.vv.GLUtils.saveAccountInfo(data);
		cc.vv.eventCustom.emit('initSelfData')
		cc.vv.GLNet.registerAccount_dwc(this.namebox.string,this.accountbox.string,this.passwordbox.string)
    }
    private onClicback(): void {
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
        cc.vv.UIMgr.close(cc.vv.GLConfig.dwc_RegisterPanel_path, cc.vv.UIMgr.closeType.destory);
    }
}
